package org.jeecg.modules.cascv.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    public static final String EXCHANGE_NAME = "boot_topic_exchange";
    public static final String IMAGEQUEUE_NAME = "image_queue";
    public static final String VIDEOQUEUE_NAME = "video_queue";
    public static final String QUEUE_NAME = "boot_queue";

    // 1 交换机
    @Bean("bootExchange")
    public Exchange bootExchange(){
        // return new TopicExchange(EXCHANGE_NAME);
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }
    //2.Queue 图片队列
    @Bean("imageQueue")
    public Queue imageQueue(){
        return QueueBuilder.durable(IMAGEQUEUE_NAME).build();
    }

    //2.Queue 视频队列
    @Bean("videoQueue")
    public Queue videoQueue(){
        return QueueBuilder.durable(VIDEOQUEUE_NAME).build();
    }

    //3.获取数据 生成文件 Queue
    @Bean("bootQueue")
    public Queue bootQueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    //3. 队列和交互机绑定关系 Binding
    /*
        1. 知道哪个队列
        2. 知道哪个交换机
        3. routing key
        noargs()：表示不指定参数
     */
    @Bean
    public Binding bindimageQueueExchange(@Qualifier("imageQueue") Queue queue,
                                     @Qualifier("bootExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("topic.image").noargs();
    }

    @Bean
    public Binding bindvideoQueueExchange(@Qualifier("videoQueue") Queue queue,
                                     @Qualifier("bootExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("topic.video").noargs();
    }

    @Bean
    public Binding bindQueueExchange(@Qualifier("bootQueue") Queue queue,
                                          @Qualifier("bootExchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("topic.file").noargs();
    }



}